unit namehelper;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, fpjson, database;

function GetBalloonName(Id: Integer): String;
function GetBlendModeName(Id: Integer): String;
function GetStateRestrictionName(Id: Integer): String;
function GetStateSvMotionName(Id: Integer): String;
function GetStateSvOverlayName(Id: Integer): String;
function GetStateAutoRemovalTimingName(Id: Integer): String;
function GetWeatherEffectName(Id: String): String;
function GetTilesetMode(Id: Integer): String;
function GetCEvTriggerName(Id: Integer): String;

function GetMessageBgTypeName(Id: Integer): String;
function GetMessagePosName(Id: Integer): String;
function GetChoicePosName(Id: Integer): String;
function GetItemTypeName(Id: Integer): String;

function FormatChar(CharId: Integer): String;
function SetVar_GetGameData(Params: TJSONArray; Db: TDatabase; ShiftArgs: Integer = 4): String;
function SetVar_GetGameData_CharDataDesc(DataType: Integer): String;
function SetVar_GetGameData_Other(DataType: Integer): String;
function SetVar_GetGameData_ActorData(Db: TDatabase; DataType: Integer): String;
function SetVar_GetGameData_EnemyData(Db: TDatabase; DataType: Integer): String;
function GetUserSelfSwitchName(Id: Integer): String;
function InnerSelfSwitchNameToUserName(InnerName: String): String;
function GetButtonName(ButtonCode: String): String;
function GetBattleMotionTypeName(Id: Integer): String;
function GetWeaponImageName(Id: Integer): String;



type
  TGetNameFn = function(Id: Integer): String;
  TGetNameWithDbFn = function(Db: TDatabase; Id: Integer): String;

resourcestring
  rsExclamation = 'Exclamation';
  rsQuestion = 'Question';
  rsMusicalNote = 'Musical note';
  rsHeart = 'Heart';
  rsAnger = 'Anger';
  rsSweatDrop = 'Sweat drop';
  rsEntanglement = 'Entanglement';
  rsSilence = 'Silence';
  rsIdea = 'Idea';
  rsSleep = 'Sleep';
  rsCustomEmotion = 'Custom emotion %d';

  rsRestrictionNone = 'No restriction';
  rsRestrictionAttackAnEnemy = 'Attack an enemy';
  rsRestrictionAttackAnyone = 'Attack anyone';
  rsRestrictionAttackAnAlly = 'Attack an ally';
  rsRestrictionCannotMove = 'Cannot move';

  rsStateSvMotionNormal = 'Normal';
  rsStateSvMotionAbnormal = 'Abnormal';
  rsStateSvMotionSleep = 'Sleep';
  rsStateSvMotionDead = 'Dead';

  rsStateSvOverlayNone = 'No overlay';
  rsStateSvOverlayPoison = 'Posion';
  rsStateSvOverlayBlindness = 'Blindness';
  rsStateSvOverlaySilence = 'Silence';
  rsStateSvOverlayRage = 'Rage';
  rsStateSvOverlayConfusion = 'Confusion';
  rsStateSvOverlayFascination = 'Fascination';
  rsStateSvOverlaySleep = 'Sleep';
  rsStateSvOverlayParalysis = 'Paralysis';
  rsStateSvOverlayCurse = 'Curse';
  rsStateSvOverlayFear = 'Fear';

  rsStateAutoRemovalTimingNone = 'None';
  rsStateAutoRemovalTimingActionEnd = 'Action end';
  rsStateAutoRemovalTimingTurnEnd = 'Turn end';

  rsWeatherEffectNone = 'None';
  rsWeatherEffectRain = 'Rain';
  rsWeatherEffectStorm = 'Storm';
  rsWeatherEffectSnow = 'Snow';

  rsWorldTypeTileset = 'World-map tileset';
  rsLocalTypeTileset = 'Local tileset';

  rsEventTriggerNone = 'No trigger';
  rsEventTriggerActionButton = 'Action button';
  rsEventTriggerPlayerTouched = 'Player touched';
  rsEventTriggerEventTouched = 'Event touched';
  rsEventTriggerAutomatic = 'Autorun';
  rsEventTriggerParallel = 'Parallel';

  rsBattleMotionType_Thrust = 'Thrust';
  rsBattleMotionType_Swing = 'Swing';
  rsBattleMotionType_Missile = 'Missile';

  rsWeaponImage_None = 'None';
  rsWeaponImage_Dagger = 'Dagger';
  rsWeaponImage_Sword = 'Sword';
  rsWeaponImage_Flail = 'Flail';
  rsWeaponImage_Axe = 'Axe';
  rsWeaponImage_Whip = 'Whip';
  rsWeaponImage_Staff = 'Staff';
  rsWeaponImage_Bow = 'Bow';
  rsWeaponImage_Crossbow = 'Crossbow';
  rsWeaponImage_Handgun = 'Handgun';
  rsWeaponImage_Claws = 'Claws';
  rsWeaponImage_Fist = 'Fist';
  rsWeaponImage_Spear = 'Spear';
  rsWeaponImage_Mace = 'Mace';
  rsWeaponImage_Wand = 'Wand';
  rsWeaponImage_Club = 'Club';
  rsWeaponImage_Chain = 'Chain';
  rsWeaponImage_Knife = 'Knife';
  rsWeaponImage_Pipe = 'Pipe';
  rsWeaponImage_Slingshot = 'Slingshot';
  rsWeaponImage_Shotgun = 'Shotgun';
  rsWeaponImage_Rifle = 'Rifle';
  rsWeaponImage_Chainsaw = 'Chainsaw';
  rsWeaponImage_EnergyBlast = 'Energy blast';
  rsWeaponImage_ShockRod = 'Shock rod';
  rsWeaponImage_Custom = 'Custom #%d';

implementation

uses
  constants, globals;

function GetBalloonName(Id: Integer): String;
begin
  case Id of
    1: GetBalloonName := rsExclamation;
    2: GetBalloonName := rsQuestion;
    3: GetBalloonName := rsMusicalNote;
    4: GetBalloonName := rsHeart;
    5: GetBalloonName := rsAnger;
    6: GetBalloonName := rsSweatDrop;
    7: GetBalloonName := rsEntanglement;
    8: GetBalloonName := rsSilence;
    9: GetBalloonName := rsIdea;
    10: GetBalloonName := rsSleep;
  else
    if (Id >= 11) and (Id <= 15) then
      GetBalloonName := rsCustomEmotion.Format([Id - 10])
    else
      GetBalloonName := '';
  end;
end;

function GetBlendModeName(Id: Integer): String;
begin
  case Id of
    0: GetBlendModeName := rsBlendModeNormal;
    1: GetBlendModeName := rsBlendModeAdditive;
    2: GetBlendModeName := rsBlendModeMultiply;
    3: GetBlendModeName := rsBlendModeScreen;
  else
    GetBlendModeName := rsUnknownParameter;
  end;
end;

function GetStateRestrictionName(Id: Integer): String;
begin
  case Id of
    0: GetStateRestrictionName := rsRestrictionNone;
    1: GetStateRestrictionName := rsRestrictionAttackAnEnemy;
    2: GetStateRestrictionName := rsRestrictionAttackAnyone;
    3: GetStateRestrictionName := rsRestrictionAttackAnAlly;
    4: GetStateRestrictionName := rsRestrictionCannotMove;
  else
    GetStateRestrictionName := '';
  end;
end;

function GetStateSvMotionName(Id: Integer): String;
begin
  case Id of
    0: GetStateSvMotionName := rsStateSvMotionNormal;
    1: GetStateSvMotionName := rsStateSvMotionAbnormal;
    2: GetStateSvMotionName := rsStateSvMotionSleep;
    3: GetStateSvMotionName := rsStateSvMotionDead;
  else
    GetStateSvMotionName := '';
  end;
end;



function GetStateSvOverlayName(Id: Integer): String;
begin
  case Id of
    0: GetStateSvOverlayName := rsStateSvOverlayNone;
    1: GetStateSvOverlayName := rsStateSvOverlayPoison;
    2: GetStateSvOverlayName := rsStateSvOverlayBlindness;
    3: GetStateSvOverlayName := rsStateSvOverlaySilence;
    4: GetStateSvOverlayName := rsStateSvOverlayRage;
    5: GetStateSvOverlayName := rsStateSvOverlayConfusion;
    6: GetStateSvOverlayName := rsStateSvOverlayFascination;
    7: GetStateSvOverlayName := rsStateSvOverlaySleep;
    8: GetStateSvOverlayName := rsStateSvOverlayParalysis;
    9: GetStateSvOverlayName := rsStateSvOverlayCurse;
    10: GetStateSvOverlayName := rsStateSvOverlayFear;
  else
    GetStateSvOverlayName := '';
  end;
end;

function GetStateAutoRemovalTimingName(Id: Integer): String;
begin
  case Id of
    0: GetStateAutoRemovalTimingName := rsStateAutoRemovalTimingNone;
    1: GetStateAutoRemovalTimingName := rsStateAutoRemovalTimingActionEnd;
    2: GetStateAutoRemovalTimingName := rsStateAutoRemovalTimingTurnEnd;
  else
    GetStateAutoRemovalTimingName := '';
  end;
end;

function GetWeatherEffectName(Id: String): String;
begin
  case Id of
    'none': GetWeatherEffectName := rsWeatherEffectNone;
    'rain': GetWeatherEffectName := rsWeatherEffectRain;
    'snow': GetWeatherEffectName := rsWeatherEffectSnow;
    'storm': GetWeatherEffectName := rsWeatherEffectStorm;
  else
    GetWeatherEffectName := Id;
  end;
end;

function GetTilesetMode(Id: Integer): String;
begin
  case Id of
    0: GetTilesetMode := rsWorldTypeTileset;
    1: GetTilesetMode := rsLocalTypeTileset;
  else
    GetTilesetMode := '';
  end;
end;

function GetCEvTriggerName(Id: Integer): String;
begin
  case Id of
    0: GetCEvTriggerName := rsEventTriggerNone;
    1: GetCEvTriggerName := rsEventTriggerAutomatic;
    2: GetCEvTriggerName := rsEventTriggerParallel;
  else
    GetCEvTriggerName := '';
  end;
end;

function GetMessageBgTypeName(Id: Integer): String;
begin
  case Id of
    0: GetMessageBgTypeName := rsShowMessageInWindow;
    1: GetMessageBgTypeName := rsShowMessageDimmedBackgroud;
    2: GetMessageBgTypeName := rsShowMessageTransparentBackgroud;
  else
    GetMessageBgTypeName := '';
  end;
end;

function GetMessagePosName(Id: Integer): String;
begin
  case Id of
    0: GetMessagePosName := rsTop;
    1: GetMessagePosName := rsVertMiddle;
    2: GetMessagePosName := rsBottom;
  else
    GetMessagePosName := rsUnknownParameter;
  end;
end;

function GetChoicePosName(Id: Integer): String;
begin
  case Id of
    0: GetChoicePosName := rsLeft;
    1: GetChoicePosName := rsHorzMiddle;
    2: GetChoicePosName := rsRight;
  else
    GetChoicePosName := rsUnknownParameter;
  end;
end;

function GetItemTypeName(Id: Integer): String;
begin
  case Id of
    0: GetItemTypeName := ItemTypeNormal;
    1: GetItemTypeName := ItemTypeKey;
    2: GetItemTypeName := ItemTypeHiddenA;
    3: GetItemTypeName := ItemTypeHiddenB;
  else
    GetItemTypeName := rsUnknownParameter;
  end;
end;

function FormatChar(CharId: Integer): String;
var
  Events: TJSONArray;
begin
  case CharId of
    -1: FormatChar := rsPlayerChar;
    0: FormatChar := rsThisEvent;
  else
    FormatChar := rsUnknownEventNumber.Format([CharId]);
    if (Game.Map <> nil) and Game.Map.Find('events', Events) then
      if (CharId >= 1) and (CharId < Events.Count) then
        if Events[CharId].JSONType = jtObject then
          FormatChar := Events.Objects[CharId].Strings['name']
        else
          FormatChar := rsUnknownEventNumber.Format([CharId]);
  end;
end;

function SetVar_GetGameData(Params: TJSONArray; Db: TDatabase; ShiftArgs: Integer = 4): String;
  function GetCharData(CharId: Integer; DataType: Integer): String;
  begin
    GetCharData := rsSetVariables_char.Format([FormatChar(CharId), SetVar_GetGameData_CharDataDesc(DataType)]);
  end;

begin
  case Params.Integers[ShiftArgs + 0] of
    0: Result := rsSetVariables_item.Format([Db.GetItemName(Params.Integers[ShiftArgs + 1])]);
    1: Result := rsSetVariables_weapons.Format([Db.GetWeaponName(Params.Integers[ShiftArgs + 1])]);
    2: Result := rsSetVariables_armours.Format([Db.GetArmourName(Params.Integers[ShiftArgs + 1])]);
    3: Result := rsSetVariables_hero.Format([Db.GetActorName(Params.Integers[ShiftArgs + 1]), SetVar_GetGameData_ActorData(Db, Params.Integers[ShiftArgs + 2])]);
    4: Result := rsSetVariables_enemy.Format([rsEnemyNumber.Format([Params.Integers[ShiftArgs + 1] + 1]), SetVar_GetGameData_EnemyData(Db, Params.Integers[ShiftArgs + 2])]);
    5: Result := GetCharData(Params.Integers[ShiftArgs + 1], Params.Integers[ShiftArgs + 2]);
    6: Result := rsSetVariables_partyMember.Format([Params.Integers[ShiftArgs + 1] + 1]);
    7: Result := SetVar_GetGameData_Other(Params.Integers[ShiftArgs + 1]);
  else
    Result := rsUnknownParameter;
  end;
end;

function SetVar_GetGameData_Other(DataType: Integer): String;
begin
  case DataType of
    0: Result := rsSetVariables_mapId;
    1: Result := rsSetVariables_numPartyMembers;
    2: Result := rsSetVariables_gold;
    3: Result := rsSetVariables_steps;
    4: Result := rsSetVariables_playTime;
    5: Result := rsSetVariables_timer;
    6: Result := rsSetVariables_saveCount;
    7: Result := rsSetVariables_battleCount;
    8: Result := rsSetVariables_victoryCount;
    9: Result := rsSetVariables_escapeCount;
  else
    Result := rsUnknownParameter;
  end;
end;

function SetVar_GetGameData_CharDataDesc(DataType: Integer): String;
begin
  case DataType of
    0: Result := rsSetVariables_char_mapX;
    1: Result := rsSetVariables_char_mapY;
    2: Result := rsSetVariables_char_direction;
    3: Result := rsSetVariables_char_screenX;
    4: Result := rsSetVariables_char_screenY;
  else
    Result := rsUnknownParameter;
  end;
end;

function SetVar_GetGameData_ActorData(Db: TDatabase; DataType: Integer): String;
begin
  case DataType of
    0: Result := Db.System.Objects['terms'].Arrays['basic'].Strings[0]; {Level}
    1: Result := Db.System.Objects['terms'].Arrays['basic'].Strings[8]; {EXP}
    2: Result := Db.System.Objects['terms'].Arrays['basic'].Strings[2]; {HP}
    3: Result := Db.System.Objects['terms'].Arrays['basic'].Strings[4]; {MP}
    4..11: Result := Db.System.Objects['terms'].Arrays['params'].Strings[DataType - 4];
  else
    Result := rsUnknownParameter;
  end;
end;

function SetVar_GetGameData_EnemyData(Db: TDatabase; DataType: Integer): String;
begin
  case DataType of
    0: Result := Db.System.Objects['terms'].Arrays['basic'].Strings[2]; {HP}
    1: Result := Db.System.Objects['terms'].Arrays['basic'].Strings[4]; {MP}
    2..9: Result := Db.System.Objects['terms'].Arrays['params'].Strings[DataType - 2];
  else
    Result := rsUnknownParameter;
  end;
end;

function GetUserSelfSwitchName(Id: Integer): String;
begin
  case Id of
    0: Result := rsSelfSwitchA;
    1: Result := rsSelfSwitchB;
    2: Result := rsSelfSwitchC;
    3: Result := rsSelfSwitchD;
  else
    Result := IntToStr(Id);
  end;
end;

function InnerSelfSwitchNameToUserName(InnerName: String): String;
begin
  if Length(InnerName) = 1 then begin
    case InnerName[1] of
      'A': Result := rsSelfSwitchA;
      'B': Result := rsSelfSwitchB;
      'C': Result := rsSelfSwitchC;
      'D': Result := rsSelfSwitchD;
    else
      Result := InnerName;
    end;
  end else
    Result := InnerName;
end;

function GetButtonName(ButtonCode: String): String;
begin
  case ButtonCode of
    'ok': GetButtonName := rsButtonOk;
    'cancel': GetButtonName := rsButtonCancel;
    'shift': GetButtonName := rsButtonShift;
    'up': GetButtonName := rsButtonUp;
    'down': GetButtonName := rsButtonDown;
    'left': GetButtonName := rsButtonLeft;
    'right': GetButtonName := rsButtonRight;
    'pageup': GetButtonName := rsButtonPageUp;
    'pagedown': GetButtonName := rsButtonPageDown;
  else
    GetButtonName := rsUnknownParameter;
  end;
end;

function GetBattleMotionTypeName(Id: Integer): String;
begin
  case Id of
    0: Result := rsBattleMotionType_Thrust;
    1: Result := rsBattleMotionType_Swing;
    2: Result := rsBattleMotionType_Missile;
  else
    Result := IntToStr(Id);
  end;
end;

function GetWeaponImageName(Id: Integer): String;
begin
  case Id of
    0: Result := rsWeaponImage_None;
    1: Result := rsWeaponImage_Dagger;
    2: Result := rsWeaponImage_Sword;
    3: Result := rsWeaponImage_Flail;
    4: Result := rsWeaponImage_Axe;
    5: Result := rsWeaponImage_Whip;
    6: Result := rsWeaponImage_Staff;
    7: Result := rsWeaponImage_Bow;
    8: Result := rsWeaponImage_Crossbow;
    9: Result := rsWeaponImage_Handgun;
    10: Result := rsWeaponImage_Claws;
    11: Result := rsWeaponImage_Fist;
    12: Result := rsWeaponImage_Spear;
    13: Result := rsWeaponImage_Mace;
    14: Result := rsWeaponImage_Wand;
    15: Result := rsWeaponImage_Club;
    16: Result := rsWeaponImage_Chain;
    17: Result := rsWeaponImage_Knife;
    18: Result := rsWeaponImage_Pipe;
    19: Result := rsWeaponImage_Slingshot;
    20: Result := rsWeaponImage_Shotgun;
    21: Result := rsWeaponImage_Rifle;
    22: Result := rsWeaponImage_Chainsaw;
    23: Result := rsWeaponImage_EnergyBlast;
    24: Result := rsWeaponImage_ShockRod;
    25 .. 30: Result := rsWeaponImage_Custom.Format([Id - 24]);
  else
    Result := IntToStr(Id);
  end;
end;

end.

